const mysql = require('mysql');

const connection = mysql.createConnection({
  host: '127.0.0.1',
  user: 'root',
  password: '123456',
  database: 'mall',
  authSwitchHandler: function (data, cb) {
    if (data.pluginName === 'mysql_native_password') {
      // 使用 mysql_native_password 身份验证插件
      const password = '123456'; // 你的密码
      cb(null, Buffer.from(password + '\0'));
    }
  }
});

connection.connect(function(err) {
  if (err) {
    console.error('Error connecting to database:', err);
    return;
  }
  console.log('Connected to database!');
});
